package demo;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @Auther: MFM
 * @Date: 2021/7/23 - 07 - 23 - 16:37
 * @version: 1.0
 */

public class StudentDemo {
    public static class Student {
        private String name;
        private int age;
        private String gender;
        private String studentNum;

        public Student(String name, int age, String gender, String studentNum) {
            this.name = name;
            this.age = age;
            this.gender = gender;
            this.studentNum = studentNum;
        }

        public Student() {
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public String getGender() {
            return gender;
        }

        public void setGender(String gender) {
            this.gender = gender;
        }

        public String getStudentNum() {
            return studentNum;
        }

        public void setStudentNum(String studentNum) {
            this.studentNum = studentNum;
        }

        @Override
        public String toString() {
            return "{" +
                    "姓名：" + name  +
                    ", 年龄：" + age +
                    ", 性别：" + gender  +
                    ", 学号：" + studentNum  +
                    '}';
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        List<Student> list = new ArrayList<>();

        while (true){
            System.out.println("请输入学生的信息，按照'姓名，年龄，性别，学号'的格式进行录入");
            String line = scanner.next();
            String[] strings = line.split("，");
            Student student = new Student(strings[0], Integer.parseInt(strings[1]), strings[2], strings[3]);
            list.add(student);

            System.out.println("是否继续添加Y/N");
            String start = scanner.next();
            if (start.equals("N")){
                break;
            }
        }

        System.out.println("录入完毕 请选择需要的进行的操作：");

        boolean flag = true;

        while(flag){
            System.out.println("1.添加学生信息");
            System.out.println("2.删除学生信息");
            System.out.println("3.修改学生信息");
            System.out.println("4.查找学生信息");
            System.out.println("5.退出");
            String choice = scanner.next();

            switch (choice){
                case "1":{
                    System.out.println("请输入要添加的学生信息，按照'姓名，年龄，性别，学号'的格式进行录入");
                    String line = scanner.next();
                    String[] strings = line.split("，");
                    Student student = new Student(strings[0], Integer.parseInt(strings[1]), strings[2], strings[3]);
                }
                break;
                case "2":{
                    System.out.println("请输入需要删除的学生的学号");
                    String studentNum = scanner.next();
                    for (int i = 0; i < list.size(); i++) {
                        if (list.get(i).getStudentNum().equals(studentNum)){
                            list.remove(i);
                            break;
                        }
                    }
                }
                break;
                case "3":{
                    System.out.println("请输入需要修改的学生的学号");
                    String studentNum = scanner.next();
                    boolean cc = false;
                    for (int i = 0; i < list.size(); i++) {
                        if (list.get(i).getStudentNum().equals(studentNum)){
                            System.out.println("请输入修改后学生信息，按照'姓名，年龄，性别，学号'的格式进行录入");
                            String strings = scanner.next();
                            String[] strings1 = strings.split("，");
                            Student student = new Student(strings1[0], Integer.parseInt(strings1[1]), strings1[2], strings1[3]);
                            list.set(i,student);
                            cc = true;
                            break;
                        }
                    }
                    if (!cc){
                        System.out.println("无此学生信息 即将退出修改功能");
                    }
                }
                break;
                case "4":{
                    System.out.println("1.查看所有学生信息 2.查看某学号学生信息");
                    String option = scanner.next();
                    if (option.equals("1")){
                        System.out.println(list);
                    }else if (option.equals("2")){
                        boolean cc = false;
                        System.out.println("请输入学号");
                        String studentNum = scanner.next();
                        for (int i = 0; i < list.size(); i++) {
                            if (list.get(i).getStudentNum().equals(studentNum)) {
                                list.get(i);
                                cc = true;
                                break;
                            }
                        }
                        if (!cc){
                            System.out.println("输入学号有误，即将退出查看功能");
                        }
                    }else {
                        System.out.println("输入选项有误，即将退出查看功能");
                    }
                }
                break;
                case "5":{
                    System.out.println("确认是否退出(请输入Y进行确认)");
                    String exit = scanner.next();
                    if (exit.equals("Y")){
                        flag=false;
                    }
                }

            }
        }
    }
}
